﻿using OASystem.BLL.IService;
using OASystem.Model;
using OASystem.ViewModel;
using System;
using System.Web.Mvc;

namespace OASystem.Controllers
{
    public class Document_wait01Controller : Controller
    {
        private ILoginService _loginService;
        private IDocument_wait01 _document_Wait01;
        public Document_wait01Controller(ILoginService loginService, IDocument_wait01 document_Wait01) 
        {
            _loginService = loginService;
            _document_Wait01 = document_Wait01;
        }
        /// <summary>
        /// 发布单人任务
        /// </summary>
        /// <param name="task">TaskList对象</param>
        /// <param name="Publisher">发布人</param>
        /// <returns></returns>
        public JsonResult Publish_task(Handle task, string Publisher)
        {
            ResponseResult result = new ResponseResult();
            result = _document_Wait01.Publish_task(task, Publisher);
            //if (result.success)
            //{
            //    Tasklist tl = result.data;
            //    int Id = Convert.ToInt32(tl.Publisher);
            //    Userinfo userinfo = _loginService.Query(a => a.UserId == Id);
            //    if (userinfo != null)
            //    {
            //        IHubContext chat = GlobalHost.ConnectionManager.GetHubContext<MyChatHub>();
            //        chat.Clients.User(Convert.ToString(tl.oneer)).add("<tr>" +
            //            "<td class='contact'>" + tl.TaskTiltle + "</td>" +
            //            "<td class='leader'>" + userinfo.EmployeeName + "</td>" +
            //            "<td class='contact'>" + tl.ReleaseTime + "</td>" +
            //            "</tr>");
            //        result.msg = "发布成功!";
            //    }
            //    else { result.success = false; result.msg = "失败"; }

            //}
            return Json(result);
        }

        /// <summary>
        /// 发布多人任务
        /// </summary>
        /// <param name="task">TaskList对象</param>
        /// <param name="Publisher">发布人</param>
        /// <param name="DepartId">部门ID</param>
        /// <returns></returns>
        public JsonResult Recode_tail01ByMore(Handle task, string Publisher, int DepartId)
        {
            //对象id字符串类型集合
            //List<string> userId = new List<string>();
            #region 多个通知
            try
            {
                #region 添加成功SingR提交
                ////实例化页面实体层对象
                ResponseResult responseResult = new ResponseResult();
                responseResult = _document_Wait01.Recode_tail01ByMore(task, Publisher, DepartId);
                ////接收添加结果是否成功
                //List<Handle> _tasklist = new List<Handle>();
                //_tasklist = Document_wait01.TasklistResults;
                //for (int i = 0; i < _tasklist.Count; i++)
                //{
                //    Tasklist tasklist1 = new Tasklist();
                //    tasklist1.oneer = _tasklist[i].oneer;
                //    userId.Add(tasklist1.oneer.ToString());
                //    //singR通知

                //}
                #endregion
                //int Id = Convert.ToInt32(_tasklist[0].Publisher);
                //Userinfo userinfo = _loginService.Query(a => a.UserId == Id);
                //IHubContext chat = GlobalHost.ConnectionManager.GetHubContext<MyChatHub>();
                //chat.Clients.Users(userId).add("<tr>" +
                //        "<td class='contact'>" + _tasklist[0].TaskTiltle + "</td>" +
                //        "<td class='leader'>" + userinfo.EmployeeName + "</td>" +
                //        "<td class='contact'>" + _tasklist[0].ReleaseTime + "</td>" +
                //        "</tr>");
                responseResult.success = true;
                responseResult.msg = "发布成功!";
                // 提交到前台处理
                return Json(responseResult);
            }
            catch (Exception)
            {
                throw;
            }
            #endregion
        }
    }
}